import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import Home from '@/views/Home.vue'
import Scrape from '@/views/Scrape.vue'
import Success from '@/views/Success.vue'
import Hotel from '@/views/Hotel.vue'
import Coupon from '@/views/Coupon.vue'
import CouponDetail from '@/views/CouponDetail.vue'
import Merchant from '@/views/Merchant.vue'
import Records from '@/views/Records.vue'
import Evaluate from '@/views/Evaluate.vue'
import Confirm from '@/views/Confirm.vue'
import Statistics from '@/views/Statistics.vue'
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/confirm',
    name: 'Confirm',
    component: Confirm
  },
  {
    path: '/scrape',
    name: 'Scrape',
    component: Scrape
  },
  {
    path: '/hotel',
    name: 'Hotel',
    component: Hotel
  },
  {
    path: '/success',
    name: 'Success',
    component: Success
  },
  {
    path: '/coupon',
    name: 'Coupon',
    component: Coupon
  },
  {
    path: '/coupon-detail/:id?',
    name: 'CouponDetail',
    component: CouponDetail
  },
  {
    path: '/merchant',
    name: 'Merchant',
    component: Merchant 
  },
  {
    path: '/records',
    name: 'Records',
    component: Records
  },
  {
    path: '/evaluate',
    name: 'Evaluate',
    component: Evaluate
  },
  {
    path: '/statistics',
    name: 'Statistics',
    component: Statistics
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

router.afterEach((to, from) => {
  window.scrollTo(0, 0)
})

export default router